<template>
    <!-- 巡检日志 -->
    <div class="app-container">
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch"
            label-width="68px">
            <el-form-item label="巡检计划" prop="title">
                <el-input v-model="queryParams.title" placeholder="请输入名称" clearable @keyup.enter.native="handleQuery" />
            </el-form-item>
            <el-form-item label="巡检时间" prop="title">
                <el-date-picker clearable v-model="queryParams.scheduleDate" type="date" value-format="yyyy-MM-dd"
                    placeholder="请选择巡检日期">
                </el-date-picker>
            </el-form-item>
            <el-form-item label="巡检状态" prop="title">
                <el-select multiple v-model="queryParams.medicineType" placeholder="请选择巡检状态" style="width: 100%">
                    <el-option label="未完成" value="1"></el-option>
                    <el-option label="已完成" value="2"></el-option>
                </el-select>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
                <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
            </el-form-item>
        </el-form>
        <el-row :gutter="10" class="mb8">
            <el-col :span="1.5">
                <el-button type="warning" plain icon="el-icon-download" size="mini" @click="handleExport">导出</el-button>
            </el-col>
        </el-row>
        <el-table v-loading="loading" :data="barrelList">
            <el-table-column label="计划巡检日期" align="center" prop="inspection_date" />
            <el-table-column label="巡检内容" align="center" prop="plan_name" />
            <el-table-column label="巡检人员" align="center" prop="recordList">
                <template slot-scope="scope">
                    <div>{{ scope.row.recordList.length > 0 ? scope.row.recordList[0].inspectionUserName : '' }}</div>
                </template>
            </el-table-column>
            <el-table-column label="巡检完成时间" align="center" prop="start_time" />
            <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
                <template slot-scope="scope">
                    <el-button size="mini" type="text" @click="handleLog(scope.row)">查看日志</el-button>
                </template>
            </el-table-column>
        </el-table>

        <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum"
            :limit.sync="queryParams.pageSize" @pagination="getList" />
    </div>
</template>

<script>
import { inspectionPlanRecord } from "@/api/site/isRecord";
export default {
    name: "Barrel",
    dicts: ['sys_normal_disable', 'his_medicine_type', 'his_dept_status'],
    data() {
        return {
            logOpen: false,
            pageSizes: [6, 10, 20, 30, 50],
            qrWidth: 70,
            qrHeight: 70,
            qrContent: "",
            // 遮罩层
            loading: false,
            // 选中数组
            ids: [],
            // 非单个禁用
            single: true,
            // 非多个禁用
            multiple: true,
            // 显示搜索条件
            showSearch: true,
            // 总条数
            total: 0,
            // 药桶编号表格数据
            barrelList: [],
            // 弹出层标题
            title: "",
            // 是否显示弹出层
            open: false,
            // 查询参数
            queryParams: {
                pageNum: 1,
                pageSize: 10,
                title: null,
                sort: null,
                dataStatus: null,
            },
            // 表单参数
            form: {
                checkedCities: []
            },
            // 表单校验
            rules: {
                medicineType: [
                    { required: true, message: "药品名称不能为空", trigger: "blur" }
                ],
                title: [
                    { required: true, message: "药品名称不能为空", trigger: "blur" }
                ],
            },
        };
    },
    created() {
        this.getList();
    },
    methods: {

        /** 查询药桶编号列表 */
        getList() {
            this.loading = true;
            this.barrelList = []
            inspectionPlanRecord(this.queryParams).then(response => {
                this.barrelList = response.rows;

                this.total = response.total;
                this.loading = false;
            });
        },
        // 取消按钮
        cancel() {
            this.open = false;
            this.reset();
        },
        // 表单重置
        reset() {
            this.form = {
                id: null,
                title: null,
                sort: null,
                createBy: null,
                createTime: null,
                updateBy: null,
                updateTime: null,
                dataStatus: null,
                delFlag: null
            };
            this.resetForm("form");
        },
        /** 搜索按钮操作 */
        handleQuery() {
            this.queryParams.pageNum = 1;
            this.getList();
        },
        /** 重置按钮操作 */
        resetQuery() {
            this.resetForm("queryForm");
            this.handleQuery();
        },


        /** 导出按钮操作 */
        handleExport() {
            this.download('his/barrel/export', {
                ...this.queryParams
            }, `巡检记录_${new Date().getTime()}.xlsx`)
        },
        //点位
        handleLog(item) {
            //跳详情
            this.$router.push("/Inspection/InspectionLogInfo?id=" + item.inspection_id);
        },
    }
};
</script>
